/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.click.app.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 *
 * @author arnold
 */
@Entity
@Table(name = "carts")
public class Cart extends BaseObject implements Serializable {

    private static final long serialVersionUID = 3832626162173359411L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;
    @ManyToOne
    private User user;
    @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "cart")
    private List<RequestClient> requests;
    private Float totalPrice;

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @return the requests
     */
    public List<RequestClient> getRequests() {
        if (requests == null) {
            requests = new ArrayList<RequestClient>();
        }
        return requests;
    }

    /**
     * @param requests the requests to set
     */
    public void setRequests(List<RequestClient> requests) {
        this.requests = requests;
    }

    /**
     * @return the totalPrice
     */
    public Float getTotalPrice() {
        if (totalPrice == null) {
            totalPrice = 0.0f;
        }
        return totalPrice;
    }

    /**
     * @param totalPrice the totalPrice to set
     */
    public void setTotalPrice(Float totalPrice) {
        this.totalPrice = totalPrice;
    }

    @Override
    public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append("id", this.id);
        return sb.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Cart other = (Cart) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 67 * hash + (this.id != null ? this.id.hashCode() : 0);

        return hash;
    }
}
